package com.cmbchina.creditcard.adapter.web;

import com.cmbchina.creditcard.application.api.CreditCardManage;
import com.cmbchina.creditcard.application.api.dto.CreditCardDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RequestMapping("/v1/credit-card")
@RestController
public class CreditCardController {
    @Autowired
    private CreditCardManage creditCardManage;

    @PostMapping(path="/{type}")
    public String create(@PathVariable(value="type", required = true) String type){
        return creditCardManage.createCard(type);
    }

    @PostMapping(path="/{id}/consume")
    public Boolean consume(@PathVariable(value="id", required = true) String id, @RequestParam(value = "amount", required = true)BigDecimal amonut){
        return creditCardManage.consume(id, amonut);
    }

    @PostMapping(path="/{id}/repay")
    public Boolean repay(@PathVariable(value="id", required = true) String id, @RequestParam(value = "amount", required = true)BigDecimal amonut){
        return creditCardManage.repay(id, amonut);
    }

    @PostMapping(path="/cards")
    public List<CreditCardDTO> cards(){
        return creditCardManage.queryCreditCardList();
    }
}
